<?php

    include '../Include/header.inc.php';
   // include '../Include/funcGestionEvenement.inc.php';
      include '../Include/funcGestionConferances.inc.php';
  
    $rempli=false; 
    
        error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
    
    
       if($_REQUEST['action']=="del"){
        
        delConferance($_REQUEST['id']);
        
        
        
    }
    
    
         if(isset($_POST['DateDebutAff'])){
           
     $_SESSION['DateDebutAff']=$_POST['DateDebutAff'];

   
    }
    
    
    
       if($_REQUEST['action']=="add"){
           
           $Titre=$_POST['Titre'];
           $Duree=$_POST['duree'];
           $Description=$_POST['Description'];
           
           $TypeEvenement=$_POST['TypeEvenement'];
           $Salle=$_POST['Salle'];
           $Conferencier=$_POST['Conferencier'];
           $Thematique=$_POST['Thematique'];
           $LangueEvenement=$_POST['LangueEvenement'];
           $DateDebut =$_POST['annee']."-".$_POST['mois']."-".$_POST['jour'].$_POST['mm'].":".$_POST['hh'];  //2012-01-19 10:15
          $Reservation=  $_POST['Reservation'];
           $Prix= $_POST['Prix'];
        addConferance(mysql_escape_string($Titre), $DateDebut,$Duree,mysql_escape_string($Description),$TypeEvenement,$Salle,$Conferencier,$Thematique,$LangueEvenement,$Reservation,$Prix);
       
        

    }
        if($_REQUEST['action']=="modif"){
                 $modif=true;
        $rempli=true;
        $v=SelectConferancesById($_REQUEST['id']);
        $_POST['titre']=$v[1];
        
        $datedebut= explode('-',$v[2]);
     
    $amj= $datedebut[0]."-".$datedebut[1]."-".substr($datedebut[2],0,2);
   
   
     
        
        $_POST['duree']=htmlentities(mysql_escape_string($v[3]));
         $_POST['Description']=htmlentities(mysql_escape_string($v[4]));
          $_POST['TypeEvenement']=htmlentities(mysql_escape_string($v[5]));
          $_POST['Salle']=htmlentities(mysql_escape_string($v[7]));
          $_POST['Conferencier']=htmlentities(mysql_escape_string($v[8]));
           $_POST['Thematique']=htmlentities(mysql_escape_string($v[9]));
           $_POST['LangueEvenement']=htmlentities(mysql_escape_string($v[10]));
    }
    
    if($_REQUEST['action']=="update"){

           $Titre=$_POST['Titre'];
           $Duree=$_POST['duree'];
           $Description=$_POST['Description'];
           
           $TypeEvenement=$_POST['TypeEvenement'];
           $Salle=$_POST['Salle'];
           $Conferencier=$_POST['Conferencier'];
           $Thematique=$_POST['Thematique'];
           $LangueEvenement=$_POST['LangueEvenement'];
           $id=$_GET['id'];
           $DateDebut =$_POST['DateDebut']." ".$_POST['heure'].":".$_POST['minute'];  //2012-01-19 10:15
          $Prix=floatval($_POST['Prix']);
          
          if(isset($_POST['Reservation'])){
            $Reservation=1;}
              else{
                 $Reservation=0; 
              
              }
              
              
        updateConferance($id,$Titre, $DateDebut,$Duree,$Description,$TypeEvenement,$Salle,$Conferencier,$Thematique,$LangueEvenement,$Prix,$Reservation);
        unset($_POST);
    }
?>

<body id="main_body" >
   <link rel="stylesheet" type="text/css" href="conf.css">
	<img id="top" src="top.png" alt="">
	<div id="form_container">
	
		<h1><a>Untitled Form</a></h1>
		<form id="form_314465" class="appnitro"  method="post" action="conferances.php?action=<?php echo isset($modif) ? 'update&id='.$_REQUEST['id'] : 'add'; ?>">
					<div class="form_description">
			<h2><?php echo isset($modif) ? 'Modifier Conference' : 'Ajouter Conference'; ?></h2>
			<p>Formulaire permettant de ajotuer et modifier les Conferences</p>
		</div>						
			<ul >
			
					<li id="li_1" >
		<label class="description" for="element_1">Titre </label>
		<div>
			<input id="element_1" required = "required" name="Titre" class="element text medium" type="text" maxlength="255" value="<?php echo $_POST['titre'] ?>"/> 
		</div> 
		</li>		<li id="li_2" >
		<label class="description" for="element_2">Date </label>

                <div>
		<select class="element select medium" id="element_5" name="DateDebut"> 
                    
                    
                      <?php
                 //      echo ($ligne[2].$ligne[3]);            
                 
//Récupération de la liste des types d'oeuvres
                                        $listeThematique = SelectParams();
                                        $ligne = ($listeThematique);
                                          $dates=(dateRange($ligne[2],$ligne[3]));
                                        
                                        
                                       foreach ($dates as $value) {
  
                                                 echo "<option value='$value'";
                                                if($rempli == true)
                                                {
                                                    if($value == $amj)
                                                    {
                                                        echo "selected='selected'";
                                                    }
                                                }
                                                echo ">".$value."</option>\n";
                                        }
                                    ?>
                    
                    


		</select>
		</div> 
                
                
                
                
                <div>
                <label class="description" for="element_2">Heure </label>
		<span>
			<input id="element_2_1" required = "required" type="number" max="23" min="0" name="heure" class="element text " size="2" type="text" maxlength="2" value="<?php  $tmp=((explode(':',$datedebut[2])));echo substr($tmp[0],3,2); ?>"/> : 
			<label>HH</label>
		</span>
		<span>
			<input id="element_2_2" required = "required"  type="number" max="59" min="0"  name="minute" class="element text " size="2" type="text" maxlength="2" value="<?php echo $tmp[1];   ?>"/> 
			<label>MM</label>
		</span>
		
                </div>
                
	
		 
		</li>		
                <li id="li_3" >
                    <li id="li_4" >
		<label class="description" for="element_4">Durée </label>
		<div>
			<input type="number" required = "required" min="0"  id="element_4" name="duree" class="element text medium" type="text" maxlength="3"  value="<?php echo $_POST['duree'] ?>"/> 
		</div>
                </li>
                <li id="li_4" >
                <label class="description" for="element_4">Prix </label>
                <div>
			<input  min="0" type="number" id="element_4" name="Prix" step="0.05" class="element text medium"  max="999"  value="<?php echo $_POST['Prix'] ?>"/> 
		 </div> 
                 </li>
                 
                    <li id="li_4" >
                <label class="description" for="element_1">Réservation obligatoire </label>
                
		 <div>
                     
			<input id="element_1_1" <?php  if($_POST['Reservation']==1)echo "checked='checked'" ?> name="Reservation" class="element checkbox" type="checkbox" value="1" />
            <label class="choice" for="element_1_1">OUI</label>
            </div>
                </li>
		
               
		
		<label class="description" for="element_3">Description </label>
		<div>
			<textarea id="element_3" required = "required" name="Description" class="element textarea medium"><?php echo $_POST['Description'] ?></textarea> 
		</div> 
		</li>		<li id="li_5" >
		<label class="description" for="element_5">Type evénement </label>
		<div>
		<select class="element select medium" id="element_5" name="TypeEvenement"> 
                    
                    
                      <?php
                                   
                     

                                        $listeThematique = SelectTB("TypeEvenement");

                                        //Parcours les types et les affiche en option
                                        while($ligne = mysql_fetch_array($listeThematique))
                                        {
                                                 echo "<option value='$ligne[0]'";
                                                if($rempli == true)
                                                {
                                                    if($ligne[0] == $_POST['TypeEvenement'])
                                                    {
                                                        echo "selected='selected'";
                                                    }
                                                }
                                                echo ">". htmlentities(mysql_escape_string($ligne[1])) ."</option>\n";
                                        }
                                    ?>
                    
                    


		</select>
		</div> 
		</li>		<li id="li_6" >
		<label class="description" for="element_6">Salle </label>
		<div>
		<select class="element select medium" id="element_6" name="Salle"> 
			
     <?php
                                   
                     
//Récupération de la liste des types d'oeuvres
                                        $listeThematique = SelectTB("Salle");

                                        //Parcours les types et les affiche en option
                                        while($ligne = mysql_fetch_array($listeThematique))
                                        {
                                                 echo "<option value='$ligne[0]'";
                                                if($rempli == true)
                                                {
                                                    if($ligne[0] == $_POST['Salle'])
                                                    {
                                                        echo "selected='selected'";
                                                    }
                                                }
                                                echo ">". htmlentities(mysql_escape_string($ligne[1])) ."</option>\n";
                                        }
                                    ?>

		</select>
		</div> 
		</li>		<li id="li_7" >
		<label class="description" for="element_7">Conferancier (<a href="conferenciers.php">Ajouter</a>)  </label>
		<div>
		<select class="element select medium" id="element_7" name="Conferencier"> 
     <?php
                                   
                                        $listeThematique = SelectTB("Conferencier");

                                        //Parcours les types et les affiche en option
                                        while($ligne = mysql_fetch_array($listeThematique))
                                        {
                                                 echo "<option value='$ligne[0]'";
                                                if($rempli == true)
                                                {
                                                    if($ligne[0] == $_POST['Conferencier'])
                                                    {
                                                        echo "selected='selected'";
                                                    }
                                                }
                                                echo ">".$ligne[1]." ".$ligne[2]."</option>\n";
                                        }
                                    ?>

		</select>
		</div> 
		</li>		<li id="li_8" >
		<label class="description" for="element_8">Thematique </label>
		<div>
		<select class="element select medium" id="element_8" name="Thematique"> 
     <?php
                                   
                    
//Récupération de la liste des types d'oeuvres
                                        $listeThematique = SelectTB("Thematique");

                                        //Parcours les types et les affiche en option
                                        while($ligne = mysql_fetch_array($listeThematique))
                                        {
                                                 echo "<option value='$ligne[0]'";
                                                if($rempli == true)
                                                {
                                                    if($ligne[0] == $_POST['Thematique'])
                                                    {
                                                        echo "selected='selected'";
                                                    }
                                                }
                                                echo ">".$ligne[1].$ligne[2]."</option>\n";
                                        }
                                    ?>
		</select>
		</div> 
		</li>	
                
                
                
                
                <li id="li_8" >
		<label class="description" for="element_8">Langue </label>
		<div>
		<select class="element select medium" id="element_8" name="LangueEvenement"> 
     <?php
                    
//Récupération de la liste des types d'oeuvres
                                        $listeThematique = SelectTB("Langue");

                                        //Parcours les types et les affiche en option
                                        while($ligne = mysql_fetch_array($listeThematique))
                                        {
                                                 echo "<option value='$ligne[0]'";
                                                if($rempli == true)
                                                {
                                                    if($ligne[0] == $_POST['LangueEvenement'])
                                                    {
                                                        echo "selected='selected'";
                                                    }
                                                }
                                                echo ">". htmlentities(mysql_escape_string($ligne[1])) ."</option>\n";
                                               
                                        }
                                    ?>
		</select>
		</div> 
		</li>
                
                
			
					<li class="buttons">
			    <input type="hidden" name="form_id" value="314465" />
			    
				<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
		</li>
			</ul>
		</form>	
		
	<img id="bottom" src="bottom.png" alt="">
        
        
        	<form id="ViewForm" class="appnitro"  method="post" action="conferances.php">
	           <div>
                       <select onChange="javascript:document.forms['ViewForm'].submit();
" class="element select medium" id="element_5" name="DateDebutAff"> 
                    
                    
                      <?php
           
//Récupération de la liste des types d'oeuvres
                                        $listeThematique = SelectParams();
                                        $ligne = ($listeThematique);
                                          $dates=(dateRange($ligne[2],$ligne[3]));
                                          echo "<option value='%'>ALL</option>";
                                        
                                       foreach ($dates as $value) {
  
                                                 echo "<option value='$value'";
                                                if(isset($_SESSION['DateDebutAff']))
                                                {
                                                    if($value == $_SESSION['DateDebutAff'])
                                                    {
                                                        echo "selected='selected'";
                                                    }
                                                }
                                                echo ">".$value."</option>\n";
                                        }
                                    ?>
                    
                    


		</select>
		</div> 
                </from>
      <table id="aff" width="100%" border="1">
            <?php
                                        //Récupération de la liste des types d'oeuvres
                                        $listeType = SelectEvenement($_SESSION['DateDebutAff']);

                                        //Parcours les types et les affiche en option
                                        while($ligne = mysql_fetch_array($listeType))
                                        {
                                            ?>
          
              <tr>
                <td width="162"><?php echo htmlentities(mysql_escape_string($ligne['Titre'])) ?> - <?php echo htmlentities(mysql_escape_string($ligne['nom'].$ligne['prenom'])) ?></td>
                <td width="22" rowspan="5"> 
                <a  onclick='return confirm("Are you sure you want to delete?")' href="conferances.php?action=del&id=<?php  echo $ligne['Id'] ?>" >
                        <img  width="20px"  height="20px" src="../pictures/Delete-icon.png" alt="Supprimer"></a>
                <a   href="conferances.php?action=modif&id=<?php  echo $ligne['Id'] ?>" >
                        <img  width="20px"  height="20px" src="../pictures/edit-icon.png" alt="Editer"></a>
                </td>
              </tr>
              <tr>
                <td>Date:<?php echo $ligne['DateDebut'] ?>  <?php echo "Durée ".$ligne['Duree'] ?>&nbsp;&nbsp;<?php echo htmlentities(mysql_escape_string($ligne['langue'])) ?></td>
              </tr>
              <tr>
                <td>Salle: <?php echo htmlentities(mysql_escape_string($ligne['nomsalle'])) ?>&nbsp;&nbsp;Réservation obligatoire :<?php if($ligne['Reservation']=="0")echo "Non"; else echo "Oui";?> </td>
              </tr>
        
              <tr>
                  <td>Thème: <?php echo htmlentities(mysql_escape_string($ligne['Theme'])) ?>&nbsp;&nbsp;type:<?php echo htmlentities(mysql_escape_string($ligne['Type'])) ?>&nbsp;&nbsp;Prix :<?php if($ligne['Prix']=="0")echo "Gratuit"; else echo $ligne['Prix'];?></td>
              </tr>
               <tr>
                <td>Description: <?php echo htmlentities(mysql_escape_string($ligne['Description'])) ?></td>
              </tr>
              <tr>
                  <td>   <br></br></td>
              </tr>
                <?php   }   ?>
            </table>
          
<?php
    include("../include/footer.php");
?>
